/**
 *
 * Copyright 2013 by Hai Nguyen
 *
 */
package com.avj.g17.chat.client;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * ServerManagemer
 *
 * @author Hai Nguyen <hain186@gmail.com>
 * @version $Id: ServerManagemer Jun 9, 2013 4:27:55 PM hainn $
 */
public class ServerManagemer implements Runnable {

    Socket client;

    public ServerManagemer(Socket client) {
        this.client = client;
    }

    @Override
    public void run() {
        try //	HAVE TO HAVE THIS FOR THE in AND out VARIABLES
        {
            Scanner in = new Scanner(client.getInputStream());	//	GET THE SOCKETS INPUT STREAM (THE STREAM THAT YOU WILL GET WHAT THEY TYPE FROM)
            PrintWriter out = new PrintWriter(client.getOutputStream());	//	GET THE SOCKETS OUTPUT STREAM (THE STREAM YOU WILL SEND INFORMATION TO THEM FROM)
            Scanner chat = new Scanner(System.in);
            while (true) //	WHILE THE PROGRAM IS RUNNING
            {
                if (in.hasNext()) {
                    String input = in.nextLine();				//	IF THERE IS INPUT THEN MAKE A NEW VARIABLE input AND READ WHAT THEY TYPED
                    System.out.println("Client Said: " + input);//	PRINT IT OUT TO THE SCREEN
                    out.println("You Said: " + input);			//	RESEND IT TO THE CLIENT
                    out.flush();
                    
                   
                }
            }
        } catch (Exception e) {
            e.printStackTrace();								//	MOST LIKELY THERE WONT BE AN ERROR BUT ITS GOOD TO CATCH IT
        }
    }
}
